<template>
  <div class="timer">系统已运行 {{ formattedTime }}</div>
</template>
  
  <script>
import { computed, onMounted, ref, onBeforeUnmount } from 'vue'
import { useStore } from 'vuex'

export default {
  setup() {
    // const store = useStore()

    // // 启动计时器
    // store.dispatch('startTimer')

    // // 获取格式化的时间
    // const formattedTime = computed(() => store.getters.formattedTime)
    const formattedTime = ref('0天00小时00分00秒')
    const timer1 = ref(null)
    onMounted(() => {
      formattedTime.value = window.api.getAndCalculateRunningTime()
      timer1.value = null
      timer1.value = setInterval(() => {
        formattedTime.value = null
        formattedTime.value = window.api.getAndCalculateRunningTime()
      }, 1000)
    })
    onBeforeUnmount(() => {
      clearInterval(timer1.value)
    })
    return {
      formattedTime
    }
  }
}
</script>
  
  <style scoped>
.timer {
  float: right;
}
</style>
  